import { errLog } from "../../../util/log";
import { Group } from "../../group";

export class GroupCluster extends Group{
    get size(){
        return 1;
    }
    get maxSize(){
        return 1;
    }

    serialize(){
        return {super:super.serialize()};
    }
    deserialize(obj){
        super.deserialize(obj.super);
        return this;
    }
}
/**
 * 
 * @param {Group} groupObj 
 * @param {any} defaultValue 
 */
export function catchDefault(groupObj, defaultValue = undefined){
    return serializeGroup(groupObj, defaultValue);
}
export function serializeGroup(groupObj, defaultValue = undefined){
    try{
        return groupObj.serialize();
    }catch(e){
        errLog(e);
        return defaultValue;
    }
}
/**
 * 
 * @param {typeof Group} GroupType
 * @param {Object} obj 
 */
export function newGroup(GroupType, obj, ...initArgs){
    return deserializeGroup(GroupType, obj, ...initArgs);
}
export function deserializeGroup(GroupType, obj, ...initArgs){
    try{
        return new GroupType().deserialize(obj);
    }catch(e){
        errLog(e);
    }
    return new GroupType(...initArgs);
}
